package basicobject

import (
	"yizhuoyan/go-study/pdfgo/handyio"
)

var trueBytes = []byte("true")
var falseBytes = []byte("false")

type Boolean struct {
	value bool
}

func (this *Boolean) Serialize(w handyio.PdfRawWriter) error {
	if this.value {
		w.WriteBytes(trueBytes)
	} else {
		w.WriteBytes(falseBytes)
	}
	return nil
}
func (this *Boolean) UnSerialize(r handyio.PdfRawReader) error {
	if r.NextBytesEquals(trueBytes) {
		this.value = true
		return nil
	}
	if r.NextBytesEquals(falseBytes) {
		this.value = false
		return nil
	}
	return r.NotSupport("not boolean")
}
